//
//  BubbleTransitionTestVC.swift
//  BubbleTransition
//
//  Created by elarc on 16/8/17.
//  Copyright © 2016年 elarc. All rights reserved.
//

import Foundation
import UIKit

 public class BubbleTransitionTestVC:UIViewController,UIViewControllerTransitioningDelegate {
    
    var transitionButton: UIButton!
    
    let transition = BubbleTransition()
    
    public override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.redColor()
        buildBtn()
        
    }
    
    func buildBtn() -> Void {
        transitionButton = UIButton(type:.Custom)
        transitionButton.frame = CGRectMake(0, 100, 100, 44)
        transitionButton.setTitle("点我呀", forState: UIControlState.Normal)
        transitionButton.backgroundColor = UIColor.brownColor()
        self.view.addSubview(transitionButton)
        transitionButton.addTarget(self, action: #selector(BubbleTransitionTestVC.clickMe), forControlEvents: UIControlEvents.TouchUpInside)
    }

     func clickMe(){
        let controller = BubbleTransitionTestModalVC()
        controller.transitioningDelegate = self
        controller.modalPresentationStyle = .Custom
        self.presentViewController(controller, animated: true) { 
            
        }
    }
    
    // MARK: UIViewControllerTransitioningDelegate
    
    public func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        transition.transitionMode = .Present
        transition.startingPoint = transitionButton.center
        transition.bubbleColor = transitionButton.backgroundColor!
        return transition
    }
    
    public func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        transition.transitionMode = .Dismiss
        transition.startingPoint = transitionButton.center
        transition.bubbleColor = transitionButton.backgroundColor!
        return transition
    }
    
}
